//
//  CommentSendViewController.m
//  WisdomZhuHai
//
//  Created by JasonLee on 15/1/27.
//  Copyright (c) 2015年 wyd. All rights reserved.
//

#import "CommentSendViewController.h"
#import "TransforController.h"
#import "ProtocolManager.h"
#import "CommentViewController.h"

@interface CommentSendViewController ()<UITextFieldDelegate>

@property(nonatomic, strong)UITextView *txt_content;

@end

@implementation CommentSendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self initView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initView{
    UIView *view_navigationBar = [TransforController shardeInstanceOfNavigationBarAndStatusBarCoverViewWithY:0];
    [self.view addSubview:view_navigationBar];
    
    UIBarButtonItem *btn_sendComment = [[UIBarButtonItem alloc]initWithTitle:@"发表" style:UIBarButtonItemStyleDone target:self action:@selector(sendComment)];
    self.navigationItem.rightBarButtonItem = btn_sendComment;
    
    UIView *view_content = [[UIView alloc]initWithFrame:CGRectMake(10, 75, 300, 300)];
    view_content.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_content];
    
    self.txt_content = [[UITextView alloc]initWithFrame:CGRectMake(11, 76, 298, 298)];
    self.txt_content.backgroundColor = [UIColor whiteColor];
//    self.txt_content.borderStyle = UITextBorderStyleRoundedRect;
    self.txt_content.font = [TransforController getFontWithFont:@"Arial" andSize:16.0];
    self.txt_content.returnKeyType = UIReturnKeySend;
//    self.txt_content.delegate = self;
//    self.txt_content.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
    [self.view addSubview:self.txt_content];
    
    self.view.backgroundColor = [TransforController getColorWithRed:225 andGreen:225 andBlue:225 andAlpha:1];
}

- (void)sendComment{
//    [[Common shareInstance]showLoadingViewWithMessage:nil];
    if([self.txt_content.text isEqualToString:@""]){
        [[Common shareInstance]showAlertViewWithTitle:nil text:@"评论内容不能为空" dismissTime:0.8];
        return;
    }
    if([ProtocolManager shareInstance].loginName != nil){
        [[ProtocolManager shareInstance]sendCommentWithTargetId:self.target_id andType:self.type andContent:self.txt_content.text andUserId:[ProtocolManager shareInstance].userId andTarget:self andSelector:@selector(sendCommentCallBack:)];
    }else{
        [[Common shareInstance]showAlertViewWithTitle:nil text:@"请先登录" dismissTime:0.8];
    }
}

- (void)sendCommentCallBack:(NSDictionary *)dic{
//    [[Common shareInstance]stopLoadingView];
    NSLog(@"%s || dic:%@", __FUNCTION__, dic);
    if(dic == nil){
        return;
    }
    if([[Common valueForKey:@"respCode" dic:dic]isEqualToString:@"000"]){
        [[Common shareInstance]showAlertViewWithTitle:nil text:@"发表成功" dismissTime:0.8];
        [self.navigationController popViewControllerAnimated:YES];
        [self.refreshDelegate refreshTableView];
    }else{
        [[Common shareInstance]showAlertViewWithTitle:nil text:@"评论发表失败" dismissTime:0.8];
    }
}

@end
